<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="description" content="" />
        <meta name="keywords" content="" />
        <meta name="author" content="Flying hormone" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta charset="UTF-8">
        <link rel="stylesheet" href="../css/media.css" />
        <link rel="stylesheet" href="../css/mui.min.css" />
        <link rel="stylesheet" href="../css/head_foot.css" />
        <script type="text/javascript" src="../js/jquery-1.9.1.js"></script>
        <script type="text/javascript" src="../js/jquery.Query.js" ></script>
        <script type="text/javascript" src="../js/jquery-cookie.js"></script>
        <script type="text/javascript" src="../js/mui.min.js"></script>
        <script type="text/javascript" src="../js/appcan.js"></script>
        <script type="text/javascript" src="../js/appcan.control.js"></script>
        <script type="text/javascript" src="../js/common.js" ></script>
		<title>模版使用</title>
		<style>
            
            i{
                font-style: normal; color: #ff3366;
            }
            
            input{ background: none; border: 1px solid;}
            input[type=text],input[type=number]{ border-color: #ccc;}
            input[type="button"]{ background: none;}
            p,span{ font-size: 0.8em; color: #999;}
            .top input{ }
            .top{ height: 5.3em;  overflow: hidden; position: relative; background: #fff; border-bottom: 1px solid #dedede;}
            .top p{ padding-top: 0; text-indent: 0; line-height: 2em; border-bottom: 1px solid #ccc; margin-top: 0.625em; padding: 0 1em; font-size: 0.8em; color: #cd4400;}
            .top span{  float: right; text-indent: 1.25em; line-height: 3.875em; margin-right: 1.25em;}
            .top a{ display: inline; text-align: center;  color: #ff3366; font-size: 1em; }
            .top>div{ height: 4.375em; width: 4.375em; border-radius: 50%; position: absolute; top: 0.625em; right: 0.625em;  overflow: hidden;}
            .top>div img{ width: 100%; height: 100%;}
            .top h3{ line-height: 3.125em; height: 3.125em; text-indent: 1em; font-size: 1.2em; color: #666; border-bottom: 1px solid #ccc; margin-bottom: 0.3125em;}
            
            
            .main{ background: #fff;}
            .main p{ border-bottom: 1px solid #ccc; text-indent: 0.625em; padding-top: 0.625em; clear: both; height: auto; overflow: hidden; position: relative;}
            .main input{ display: inline-block; width: 50%; margin-bottom: 0; padding: 0; font-size: 1em; text-indent: 0.3em; 
                line-height: 2.2em;
                height: 2.2em;
                color: #000;}
            .main i{  font-style: normal; width: 30%; float: left; text-align: right; line-height: 2.5em;}
            
            .main textarea{ width: 50%; margin-bottom: 0; padding: 0 0.625em;  font-size: 0.8em; line-height: 1.25em; height: 6.25em;}
            .main input[type=submit]{ background: #ff3366; border: none; width: 40%; position: relative; left: 50%; margin-bottom: 1em;}
            #upload0{ display: none;}
            .main h3{ line-height: 3.125em; height: 3.125em; text-indent: 1em; font-size: 1.2em; color: #666; border-bottom: 1px solid #ccc;}
            .main h3 a{ font-size: 0.8em; color: #666; float: right; margin-right: 1em; border: 1px solid #ccc; height: 1.875em; line-height: 1.875em; text-align: center; text-indent: 0; padding: 0 0.375em; border-radius: 0.3125em; margin-top: 0.625em;}
            .main p img{ height: 2.5em; position: absolute; left: 1.25em;}
            
            .quyu2{ margin-top: 0.625em;}
            .quyu2 .top{ height: 3.125em;}
            .main h3{ font-size: 0.8em;}
            .main p span{ display: block; width: 80%; font-size: 0.8em; text-align: left; float: right;}
            .main select{ width: 67%; font-size: 0.8em; line-height: 1.5em;}
            option{ font-size: 0.4em;}
            .fenlei{ position: relative;}
            .main p.fenlei span{     position: absolute;
                display: block;
                right: 1em;
                top: 50%;
                width: 1em;
                font-size: 1.25em;
                float: right;
                margin-top: -0.625em;}
            .fenlei select{ margin: 0; padding: 0.625em; background: none; position: absolute; z-index: 100;}
            .main .tuijian span{ position: absolute; right: 1em; top: 1em; width: 13%; color: #FF3366;}
            .main .tuijian input{ width: 30%;}
            .btn{ }
            .btn p{ text-align: right; padding-top: 0.625em;}
            .btn span{    line-height: 2em; display: inline-block; width: 40%; border: 1px solid #FF3366; background: #ff3366; text-align: center;  border-radius: 0.3125em;}
            .btn span a{ color: #fff; }
            .btn span.action{ color: #ff3366; background: #fff;margin-left: 10%;}
            .btn span.action a{ color: #ff3366; background: #fff; }
            
            @media screen and (max-width: 400px) {
                .main i{ font-size: 0.8em; width: 40%;}
                .main input{ width: 50%;}
                .main textarea{ width: 50%;}
                .top{ height: 6.5em;}
            }
            .main input.time{background: #ccc;}
            p.indexquyu{ line-height: 1.5em;text-indent: 0; }
            .indexquyu a{ margin-bottom:1em; margin-right:1em; color:#878787; font-size: 0.8em; display: inline-block; border: 1px solid #ccc; text-indent: 0; padding: 0.1em 0.75em; border-radius:0.3em;}
            .indexquyu a.active{ color: #fff; background: #ff3366; border-color: #ff3366;}
        </style>
	</head>

	<body>
		<header>
			<a class="leftleft"></a>
			<h1>模版使用</h1>
		</header>
		<section class="quyu">
			<form>
				<div class="top">
					<p>当前发布位置为<i id="typeName" style="color: #cd4400"></i>，资费为<i id="sysParam"></i></p>
					<h3><a>完善名片</a></h3>
				</div>
				<div class="main">
					<h3>编辑名片<a onclick="openUrl('my_card.html?returnUrl=moban', 'my_card');">选择其他名片</a></h3>
					<p><i>名称或店铺名：</i><input type="text" value="" id="cardName" placeholder="请输入店铺名称" readonly="readonly"/></p>
					<p><i>详细地址：</i><input type="text" value="" id="address" placeholder="请输入详细地址"  readonly="readonly"/></p>
					<p><i>联系电话：</i><input type="number" value="" id="telphone" placeholder="请输入联系电话"  readonly="readonly"/></p>
					<p style="border: none;"><i>经营范围：</i><textarea type="text" value="" id="region" readonly="readonly"/></textarea></p>
				</div>
			</form>
		</section>
		
		<section class="quyu2">
			<form id="fabuForm">
			    <input type="hidden" name="cardId" id="cardId" />
				<div class="top">
					<h3><a>发布补充</a></h3>
				</div>
				<div class="main">
					<h3>选择线上广告发布时间</h3>
					<p><i>开始时间：</i><input class="time" type="date" value="" placeholder="" name="startTime" id="startTime" /></p>
					<p>
						<i>截止时间：</i>
						<input class="time" type="date" value="" placeholder="" name="endTime" id="endTime"/>
						<span>注：最长发布不得超过10天，四大模块为6个月</span>
					</p>
					<h3>线下活动</h3>
					<p><i>开始时间：</i><input class="time" type="date" value="" placeholder="" name="offlineTime" id="offlineTime" /></p>
					<p><i>截止时间：</i><input class="time" type="date" value="" placeholder="" name="offlineEndTime" id="offlineEndTime" /></p>
                    <p style="display: none;">
                        <i>线下活动地点：</i>
                        <input type="text" value="" placeholder="" name="offlinePlace" id="offlinePlace"/>
                    </p>
					<p>线下活动所在区域：<span id="actregion"></span></p>
                    <p class="indexquyu">
                       
                    </p>
					<p class="fenlei">
						<i>分类：</i>
						<select name="cateId">
							<option value="">所有</option>
						</select>
						<span class="bottombottom"></span>
					</p>
					<p class="tuijian">
						<i>推荐码：</i>
						<input type="text" id="payCode" value="" placeholder="无则 不填" />
                        <span id="payCodeState">待检测</span>
					</p>
				</div>
			</form>
		</section>
		<section class="btn">
			<p>费用共<i id="amount">0</i>元</p>
			<span  id="preview" class="action"><a>预览</a></span>
			<span id="nextStep" ><a >发布</a></span>
		</section>

		<footer>
			<nav class="mui-bar mui-bar-tab">
				<a href="javascript:;" id="tcIndex">
                    <img src="../img/shouye2.png" />
                    <span class="mui-tab-label">首页</span>
                </a>
                <a class="action" href="javascript:;" id="myfabu">
                    <img src="../img/fabu2b.png" />
                    <span class="mui-tab-label">发布</span>
                </a>
                <a href="javascript:;" id="myInfo">
                    <img src="../img/mine.png" />
                    <span class="mui-tab-label">我的</span>
                </a>
			</nav>
		</footer>
	<script>
	    $(document).ready(function(){
	        //查询 分类
            appcan.ajax({
                type:"get",
                url:host+"/getAreaByName.json?cityName="+appcan.locStorage.getVal("ipcity"),
                dataType:"json",
                contentType: "application/json",
                success : function(dataResult) {
                    console.log(dataResult);
                    var actStr = '';
                    // 获取区域数据
                    for(var i=0;i<dataResult.data.length;i++){
                        actStr +='<a>'+dataResult.data[i].cityname+'</a>';
                    }
                    $(".indexquyu").html(actStr);
                    
                    $(".indexquyu a").click(function(){
                       if($(this).hasClass("active")){
                           $(this).removeClass("active");
                       }else{
                           $(".indexquyu a").removeClass("active");
                           $(this).addClass("active");
                       };
                       var ccc = "";
                       for(var i=($(".indexquyu .active").length); i>0; i--){
                           ccc = $(".indexquyu .active").eq(i-1).text() + (ccc.length == 0 ? "" : ("," + ccc));
                           $("#actregion").text(ccc);
                       };
                    });
                }
            })
	    });
	</script>
    <script>
        var type = getVal("type") || "0";
        var actId = getVal("actId");
        console.log(actId);
        var num = type.substring(1,type.length);
        var payCodeId = "";
        var unit = "";
        var price = 0;
        var totalPrice = 0;//推广总共花费
        var endTime = "";
        var state = "1";
        
        // 获取金额
        appcan.ajax({
           type:"get",     
           url:host+"/getActFeeBy.json?actType="+type,
           dataType:"json",
           contentType: "application/json",
           success : function(dataResult) {
               if(!!dataResult.data){
                   if(dataResult.data.unit == "day"){
                       unit = "天";
                       price = dataResult.data.amount;
                       $("#sysParam").text(dataResult.data.amount + "元/天");
                   }else if(dataResult.data.unit == "month"){
                       unit = "月";
                       price = dataResult.data.amount;
                       $("#sysParam").text(dataResult.data.amount + "元/月");
                   }else{
                       $("#sysParam").text("免费试用");  
                   }
                   totalPrice = dataResult.data.amount||0;
                   $("#amount").text(dataResult.data.amount||0);
               }
           }
       })
       
        $(function(){
            // 推荐码验证
            $("#payCode").blur(function(){
               $("#amount").text(totalPrice);
               if(!!!$("#payCode").val()){
                   $("#payCodeState").html("待审核");
                   return false;
               }
               appcan.ajax({
                   type:"get",     
                   url:host+"/checkPayCode.json?payCode="+$("#payCode").val(),
                   dataType:"json",
                   contentType: "application/json",
                   success : function(dataResult) {
                       if(dataResult.status == 200){
                           payCodeId = dataResult.data.id;
                           $("#payCodeState").html("可用");
                           $("#amount").text("0");
                       }else{
                           $("#payCodeState").html("不可用");
                       }
                   }
               })
            })
            
            if(!!getVal("actId")){
                // 编辑页面获取数据
                appcan.ajax({
                    type:"post",
                    url:host+"/getActive.json?actId="+getVal("actId"),
                    dataType:"json",
                    contentType: "application/json",
                    success : function(dataResult) {
                        if(!!dataResult.data){
                            var data = dataResult.data;
                            state = data.state;
                            $("#startTime").val(data.startTime);
                            $("#endTime").val(data.endTime);
                            endTime = data.endTime;
                            if(!!data.startTime && !!data.endTime){
                                $("#amount").text(0);
                            }
                            $("#offlineTime").val(data.offlineTime);
                            $("#offlineEndTime").val(data.offlineEndTime);
                            $("#offlinePlace").val(data.offlinePlace);
                            $("#actregion").text(data.region || '')
                            $("#cateId").val(data.cateId);
                            $("#endTime").blur();
                        }
                    }
                })
            }
            
            // 若类型传参错误 则返回上一个页面
            if(type == "0"){
                appcan.window.close(-1); 
                return false;
            }
            
            switch(type){
                case "A1":
                    $("#typeName").text("名优活动");
                    break;
                case "B2":
                    $("#typeName").text("同城购活动");
                    break;
                case "C1":
                    $("#typeName").text("超市模块");
                    break;
                case "D1":
                    $("#typeName").text("婴育模块");
                    break;
                case "E1":
                    $("#typeName").text("车辆模块");
                    break;
                case "F1":
                    $("#typeName").text("房产模块");
                    break;
                case "C2":
                    $("#typeName").text("超市模块");
                    break;
                case "D2":
                    $("#typeName").text("婴育模块");
                    break;
                case "E2":
                    $("#typeName").text("车辆模块");
                    break;
                case "F2":
                    $("#typeName").text("房产模块");
                    break;
            }
            
            //类型为1 隐藏类型2
            //位置代码
            //$("#typeNum").text(num);
            $("#code").val(type);
            if(num == 1){
                $("#type2").hide();
            }else{
                $("#type1").hide();
            }
            
            var cardId = getVal("cardId");
            if(!!cardId){
                //获取修改对象
                appcan.ajax({
                   type:"post",
                   url:host+"/getCard.json?cardId="+cardId,
                   dataType:"json",
                   contentType: "application/json",
                   success : function(dataResult) {
                       var data = dataResult.data; 
                       $("#cardId").val(data.id);
                        $("#cardName").val(data.cardName);
                        $("#address").val(data.address);
                        $("#telphone").val(data.telphone);
                        $("#region").val(data.region);
                   }
               })
            }else{
                // 获取默认名片
                appcan.ajax({
                   type:"get",     
                   url:host+"/getCardList.json?userId="+appcan.locStorage.getVal("userId"),
                   dataType:"json",
                   contentType: "application/json",
                   success : function(dataResult) {
                       var data = dataResult.data;
                        if(data.length > 0){
                            $("#cardId").val(data[0].id);
                            $("#cardName").val(data[0].cardName);
                            $("#address").val(data[0].address);
                            $("#telphone").val(data[0].telphone);
                            $("#region").val(data[0].region);
                        }
                   }
               })
            }
            
            // 获取分类
            var baseParam = {
                pid : '2'
            }
            var param = serializePageJson(1, 100, baseParam);
            appcan.ajax({
               type:"post",     
               url:host+"/getCateByPid.json",
               data:param,
               dataType:"json",
               contentType: "application/json",
               success : function(dataResult) {
                    var data = dataResult.data.dataList;
                    var str = "";
                    for(var i = 0; i < data.length; i++){
                        str+='<option value="'+data[i].id+'">'+data[i].cateName+'</option>';
                    }
                    $(".fenlei select").append(str);
               }
           })
            
            // 预览
            $("#preview").click(function(){
                saveAct("preview");
            })
            
            // 发布
            $("#nextStep").click(function(){
                saveAct("nextStep");
            })
            
            $("#startTime, #endTime").blur(function(){
                if($.trim($("#startTime").val()).length != 0 && $.trim($("#endTime").val()).length != 0){
                    var bng = $("#startTime").val();
                    var end = $("#endTime").val();
                    var bngDate = new Date(bng.substr(0,4),bng.substr(5,2)-1,bng.substr(8,2));
                    var endDate = new Date(end.substr(0,4),end.substr(5,2)-1,end.substr(8,2));
                    var days = (endDate.getTime()-bngDate.getTime())/24/60/60/1000 + 1;
                    // 若endTime不为空 则为续期
                    var oldEndDate = "";
                    var oldDays = 0;
                    if(!!endTime){
                        var oldEndDate = new Date(endTime.substr(0,4),endTime.substr(5,2)-1,endTime.substr(8,2));
                        var oldDays = (oldEndDate.getTime()-bngDate.getTime())/24/60/60/1000 + 1;
                        if(state != "2" || days<oldDays){
                            oldDays = 0;
                        }
                    }
                    if(days < 0){
                        alert("截至时间必须大于开始时间！");
                        $("#endTime").val("");
                        return false;
                    }
                    if(unit == "天"){
                        if(days > 10){
                            alert("最长发布不得超过10天！");
                            $("#endTime").val("");
                            return false;
                        }
                        $("#amount").text(price*(days-oldDays));
                    }else if(unit == "月"){
                        if(days > 180){
                            alert("最长发布不得超过6个月！");
                            $("#endTime").val("");
                            return false;
                        }
                        $("#amount").text((price/30)*(days-oldDays));
                    }
                }
            });
            
            // 异步保存当前页面信息
            function saveAct(obj){
                // 数据校验
                if($.trim($("#cardId").val()).length == 0){
                    appcan.window.alert({
                        title:'提示',
                        content:'请先选择名片',
                        buttons:'确定'
                    });
                    return false;
                }
                if($.trim($("#startTime").val()).length == 0){
                    appcan.window.alert({
                        title:'提示',
                        content:'请选择开始时间',
                        buttons:'确定'
                    });
                    return false;
                }
                if($.trim($("#endTime").val()).length == 0){
                    appcan.window.alert({
                        title:'提示',
                        content:'请选择结束时间',
                        buttons:'确定'
                    });
                    return false;
                }
                if($.trim($("#actregion").text()).length == 0){
                    appcan.window.alert({
                        title:'提示',
                        content:'所在市区域不能为空',
                        buttons:'确定'
                    });
                    return false;
                }
                
                // 活动状态
                var state = "2";
                if(obj == "preview"){
                    state = "1";
                }
                var baseParam = {
                    userId : appcan.locStorage.getVal("userId"),
                    id : actId,
                    amount : $("#amount").text(),
                    region : $("#actregion").text(),
                    payCodeId : payCodeId,
                    state : state
                };
                
                var result = null;
                // 有推荐码 或者价格是0 直接发布
                if(obj == "preview" || !!payCodeId || $("#amount").text() == "0"){
                    var param = $("#fabuForm").serializeJson(baseParam);
                    appcan.ajax({
                       type:"post",
                       async:false,       
                       url:host+"/publicAct.json",
                       data:param,
                       dataType:"json",
                       contentType: "application/json",
                       success : function(dataResult) {
                            result = dataResult;
                            if(obj == "preview"){
                               if(result.status > 0){
                                   if(type=="C1" || type=="C2" || type=="D1" || type=="D2"){
                                       openUrl("../page/info_goods.html?actId="+actId,"info_goods");
                                   }else{
                                       openUrl("../page/info.html?actId="+actId,"actInfo");
                                   }
                               }
                            }else{
                               if(result.status > 0){
                                   alert("操作成功");
                                    appcan.locStorage.remove("actId");
                                    openUrl("../index.html","index");
                               }
                           }
                       }
                   })
                }else{
                    baseParam.payCodeId = "";
                    var param = $("#fabuForm").serializeJson(baseParam);
                    appcan.locStorage.setVal("param",param);
                    openUrl("../user/zhifu.html","zhifu");
                }
            }
        })
        
    </script>
	</body>

</html>